package com.example.dagger3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.example.dagger3.object.A;
import com.example.dagger3.object.B;
import com.example.dagger3.object.ObjectForMainModule;
import com.example.dagger3.object.ObjectForTestSubModule;
import com.example.dagger3.object.User;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import dagger.Lazy;

public class MainActivity extends AppCompatActivity {


    @Inject
    ObjectForMainModule mainModule;
    @Inject
    ObjectForTestSubModule testSubModule;

    @Inject
    A a;
    @Inject
    B b;

    @Named("key1")
    @Inject
    User user;

    @Named("key2")
    @Inject
    User user2;

    @Named("key1")
    @Inject
    Lazy<User> lazy;  //   Lazy单例  懒加载，就是需要用的时候就去加载

    @Named("key2")
    @Inject
    Provider<User> provider;   //  Provider 不是单例   懒加载，

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DaggerMainComponent.create()
                .getTestSubComponent()
                .injectMainActivity(this);

        Log.e("注入成功", " " + mainModule.hashCode());
        Log.e("注入成功", " " + testSubModule.hashCode());
        Log.e("注入成功", " " + a.hashCode());
        Log.e("注入成功", " " + b.hashCode());
        Log.e("注入成功", " " + user.toString());
        Log.e("注入成功", " " + user2.toString());
        Log.e("注入成功", " " + lazy.get().toString());
        Log.e("注入成功", " " + provider.get().toString());
        Log.e("注入成功", " " + lazy.get().hashCode());
        Log.e("注入成功", " " + lazy.get().hashCode());
        Log.e("注入成功", " " + provider.get().hashCode());
        Log.e("注入成功", " " + provider.get().hashCode());

    }
}